package com.swpu.cbg.cnshop.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.swpu.cbg.cnshop.R;
import com.swpu.cbg.cnshop.bean.Image;
import com.swpu.cbg.cnshop.bean.Order;
import com.swpu.cbg.cnshop.bean.OrderItem;
import com.swpu.cbg.cnshop.widget.NineGridlayout;


import java.util.ArrayList;
import java.util.List;


public class MyOrderAdapter extends BaseAdapter<Order,BaseViewHolder> {


    public MyOrderAdapter(Context context, List<Order> datas,int itemview) {
        super(context, datas,itemview);
    }


    @Override
    void bindData(BaseViewHolder holder, int position) {
        Order item = mDatas.get(position);
        String s = item.getOrderNum();
        holder.getTextView(R.id.txt_order_num).setText("订单号：" + item.getOrderNum().toString());
        holder.getTextView(R.id.txt_order_money).setText("实付金额： ￥：" + item.getAmount());

        TextView txtStatus = holder.getTextView(R.id.txt_status);


        switch (item.getStatus()) {

            case Order.STATUS_SUCCESS:
                txtStatus.setText("成功");
                txtStatus.setTextColor(Color.parseColor("#ff4CAF50"));
                break;


            case Order.STATUS_PAY_FAIL:
                txtStatus.setText("支付失败");
                txtStatus.setTextColor(Color.parseColor("#ffF44336"));
                break;

            case Order.STATUS_PAY_WAIT:
                txtStatus.setText("等待支付");
                txtStatus.setTextColor(Color.parseColor("#ffFFEB3B"));
                break;

        }


        NineGridlayout nineGridlayout = (NineGridlayout) holder.getView(R.id.iv_ngrid_layout);
        List<Image> images = getAllWareImage(item);
        nineGridlayout.setImagesData(images);

    }

    private List<Image> getAllWareImage(Order item) {
        List<Image> images = new ArrayList<>();
        if (item != null) {
            for (OrderItem orderItem : item.getItems()) {
                if (orderItem.getWares() == null) {
                    images.add(new Image("http://7mno4h.com2.z0.glb.qiniucdn.com/s_recommend_55c1e8f7N4b99de71.jpg", 50, 50));

                } else {
                    images.add(new Image(orderItem.getWares().getImgUrl(), 50, 50));
                }
            }
        }
        return images;
    }

}
